((typeof self !== 'undefined' ? self : this)["webpackJsonpproduct_manager"] = (typeof self !== 'undefined' ? self : this)["webpackJsonpproduct_manager"] || []).push([[29],{

/***/ "d9ef":
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);

// EXTERNAL MODULE: ./node_modules/core-js/modules/es.array.concat.js
var es_array_concat = __webpack_require__("99af");

// EXTERNAL MODULE: external "Vue"
var external_Vue_ = __webpack_require__("8bbf");
var external_Vue_default = /*#__PURE__*/__webpack_require__.n(external_Vue_);

// EXTERNAL MODULE: ./src/store/index.ts + 4 modules
var store = __webpack_require__("0613");

// CONCATENATED MODULE: ./src/api/websocket/websocketLifecycle.ts


/*
* 如果你需要使用store，只需要把下面的代码取消注释即可
*/


var websocketLifecycle_store;

if (external_Vue_default.a.prototype.isPortal) {
  websocketLifecycle_store = window[window.poolName].store;
} else {
  websocketLifecycle_store = store["a" /* default */];
}

var scopeName = "product_manager";

function commit(funcStr, data) {
  websocketLifecycle_store.commit("".concat(scopeName, "/").concat(funcStr), data);
}

var ws = {
  // onopen (event) {
  //     // 当 readyState === 'OPEN' 时,会执行这里
  // },
  onerror: function onerror(error) {
    console.log('websocket connect is error...', error); // 当websocket出错时,会执行这里
  },
  onmessage: function onmessage(mode, event) {
    // websocket接收到推送的消息
    var message = JSON.parse(event.data);

    if (!message) {
      return;
    }

    if (mode === 'productManager') {
      switch (message.key) {
        case 'all':
          commit('setProductManagerAll', message.data);
          break;

        case 'bom':
          commit('setBom', message.data);
          break;

        case 'cur_day_issued_data':
          commit('setCurDayIssuedData', message.data);
          break;

        case 'ten_day_data':
          commit('setTenDayData', message.data);
          break;

        case 'pass_rate':
          commit('setPassRate', message.data);
          break;

        default:
          break;
      }
    } else {
      switch (message.key) {
        case 'all':
          commit('setBoardAll', message.data);
          break;

        case 'semi_finished_check_result':
          commit('setSemiFinishCheckResult', message.data);
          break;

        case 'finished_check_result':
          commit('setFinishedCheckResult', message.data);
          break;

        case 'quality_monitor':
          commit('setQualityMonitor', message.data);
          break;

        case 'total_quality_monitor':
          commit('setTotalQualityMonitor', message.data);
          break;

        case 'alarm_data':
          commit('setAlarmData', message.data);
          break;

        case 'day_product_trend':
          commit('setDayProductTrend', message.data);
          break;

        case 'digit_twin_unit':
          commit('setDigitTwinUnit', message.data);
          break;

        case 'digit_status':
          commit('setDigitStatus', message.data);
          break;

        default:
          break;
      }
    } // console.log(message)

  },
  onclose: function onclose(event) {
    // 当 readyState === 'CLOSED' 时,会执行这里
    console.log('websocket connect is closed...');
  }
};
/* harmony default export */ var websocketLifecycle = (ws);
// CONCATENATED MODULE: ./src/plugins/websocketJs.ts


var websocketJs_ws = {};
var websocketUrl = "".concat((location.protocol === "https:" ? "wss://" : "ws://") + location.host);
var timeout = 5000;
var timer = {};
var noConnect = {}; // websocket路径携带organization
// function getWebsocketHeader () {
//     const url = location.pathname.split('/')
//     if (url.length <= 3) {
//         return websocketUrl
//     }
//     const urlObj = new URL(websocketUrl)
//     return `${urlObj.origin}/${url[1] + urlObj.pathname}`
// }

/**
 * @function 创建一个新的websocket
 * @param key {symbol} 每次创建一个新的ws的时候传入一个新的symbol,
 * 这个symbol即表示此次连接的唯一id，后续关闭连接的时候依然传入此symbol
 * @return void
 */

function createWs(key, mode) {
  // 创建websocket 实例
  websocketJs_ws[key] = new WebSocket("".concat(websocketUrl, "/").concat(mode === 'productManager' ? 'ws/produce_manage' : 'ws/digit_twin'));
  initEventHandler(key, mode);
}

function initEventHandler(key, mode) {
  // WebsocketLifecycle.onopen && (ws.onopen = WebsocketLifecycle.onopen)
  websocketJs_ws[key].onmessage = websocketLifecycle.onmessage.bind(null, mode);

  websocketJs_ws[key].onclose = function () {
    websocketLifecycle.onclose();

    if (noConnect[key]) {
      delete noConnect[key];
      return;
    }

    timer[key] = setTimeout(function () {
      createWs(key, mode);
    }, timeout);
  };
}

function sendWsDataToApp(key, data) {
  data && websocketJs_ws[key].send(data);
}

function closeWs(key) {
  noConnect[key] = true;
  clearTimeout(timer[key]);
  delete timer[key];
  websocketJs_ws[key].close();
  delete websocketJs_ws[key];
}

/* harmony default export */ var websocketJs = __webpack_exports__["default"] = (function (_ref) {
  var Vue = _ref.Vue;
  // 定义websocket向后端发送数据的方法, 在组件中使用: this.$ws_send('123'); 在js文件中使用: Vue.prototype.$ws_send('123')
  Vue.prototype.$wsSend = sendWsDataToApp;
  Vue.prototype.$closeWs = closeWs;
  Vue.prototype.$createWs = createWs;
});

/***/ })

}]);